package com.itheima.demo3;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test {
    public static void main(String[] args){
        String info = "10001,张无忌,男,2023-07-22 11:11:12,东湖-黄鹤楼#10002,赵敏,女,2023-07-22 09:11:21,黄鹤楼-归元禅寺#10003,周芷若,女,2023-07-22 04:11:21,木兰文化区-东湖#10004，小昭,女,2023-07-22 08:11:21,东湖#10005，灭绝,女,2023-07-22 17:11:21,归元禅寺" ;
        info = info.replace('，', ',');
        String[] StudentInfos = info.split("#");
        List<Student> students = new ArrayList<>();
        for(String str : StudentInfos){
            Student student = Student.parseStudent(str);
            students.add(student);
        }
        Map<String, Integer> map = new HashMap<>();
        for(Student student : students){
            for(String address : student.getAddress()){
                map.put(address, map.getOrDefault(address, 0) + 1);
            }
        }

        String address = "";
        int num = 0;
        for (Map.Entry<String, Integer> entry : map.entrySet()){
            System.out.println("“" + entry.getKey() + "”" + "选取次数为：" + entry.getValue());
            if(address.equals("")){
                address = entry.getKey();
                num = entry.getValue();
            }
            else if(entry.getValue() > num){
                address = entry.getKey();
                num = entry.getValue();
            }
        }
        System.out.println("最终选取的地点为：" + address);
        for(Student student : students){
            boolean flag = false;
            for(String str : student.getAddress()){
                if(str.equals(address)){
                    flag = true;
                    break;
                }
            }
            if(!flag){
                System.out.println("学生：" + student.getName() + "没选择该地点");
            }
        }
    }
}
